
package com.itheima.health.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.mapper.UserMapper;
import com.itheima.health.pojo.Permission;
import com.itheima.health.pojo.User;
import com.itheima.health.service.UserService;
import com.itheima.health.vo.RoleVO;
import com.itheima.health.vo.UserVO;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**

 */

@Transactional
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements UserService {

    @Override
    public UserVO findUserDetailsByUsername(String username) {

        // 1.根据账号查询用户信息
        UserVO userVO = baseMapper.findUserByUsername(username);
        //2.根据用户id查询对应角色以及关键字
        List<RoleVO> roleVOList = baseMapper.findRoleByUId(userVO.getId());
        //3.根据角色id查询对应的权限级关键字
        for (RoleVO roleVO : roleVOList) {
            List<Permission> permissionList = baseMapper.findPermissionByRoleId(roleVO.getId());
            roleVO.setPermissionList(permissionList);
        }
        userVO.setRoles(roleVOList);
        System.out.println("---------------------------"+userVO.toString());
        return userVO;
    }
}

